<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/><meta name="exporter-version" content="Evernote Mac 6.0.5 (451190)"/><meta name="altitude" content="33"/><meta name="author" content="rainy"/><meta name="created" content="2015-01-13 03:50:15 +0000"/><meta name="latitude" content="23.1283725899424"/><meta name="longitude" content="113.311547826377"/><meta name="source" content="desktop.mac"/><meta name="updated" content="2015-01-13 04:07:53 +0000"/><title>Maven-tomcat部署过程</title></head><body>
<div>1、首先你得有个tomcat，到官网下载了一个apache-tomcat-7.0.57.</div>
<div><br/></div>
<div>2、修改apache-tomcat-7.0.57/conf/tomcat-users.xml，添加manager用户：</div>
<div><br/></div>
<div>
<hr/></div>
<div>&lt;tomcat-users&gt;</div>
<div>
<div>&lt;!--</div>
<div>  NOTE:  By default, no user is included in the "manager-gui" role required</div>
<div>  to operate the "/manager/html" web application.  If you wish to use this app,</div>
<div>  you must define such a user - the username and password are arbitrary.</div>
<div>--&gt;</div>
<div>&lt;!--</div>
<div>  NOTE:  The sample user and role entries below are wrapped in a comment</div>
<div>  and thus are ignored when reading this file. Do not forget to remove</div>
<div>  &lt;!.. ..&gt; that surrounds them.</div>
<div>--&gt;</div>
<div>&lt;!--</div>
<div>  &lt;role rolename="tomcat"/&gt;</div>
<div>  &lt;role rolename="role1"/&gt;</div>
<div>  &lt;user username="tomcat" password="tomcat" roles="tomcat"/&gt;</div>
<div>  &lt;user username="both" password="tomcat" roles="tomcat,role1"/&gt;</div>
<div>  &lt;user username="role1" password="tomcat" roles="role1"/&gt;</div>
<div>--&gt;</div>
<div>  <span style="background-color: rgb(255, 250, 165);-evernote-highlight:true;">&lt;role rolename="manager-gui"/&gt;</span></div>
<div><span style="background-color: rgb(255, 250, 165);-evernote-highlight:true;">  &lt;role rolename="manager-script"/&gt;</span></div>
<div><span style="background-color: rgb(255, 250, 165);-evernote-highlight:true;">  &lt;user username="manager" password="admin" roles="manager-gui, manager-script"/&gt;</span></div>
</div>
<div>&lt;/tomcat-users&gt;</div>
<div>
<hr/></div>
<div><br/></div>
<div>3、启动tomcat，<a href="http://localhost:8080/manager/html">http://localhost:8080/manager/html</a>，用户名和密码就是上一步设置的manager/admin：</div>
<div><img src="Maven-tomcat%E9%83%A8%E7%BD%B2%E8%BF%87%E7%A8%8B.resources/BD6D066C-940D-49A2-80E4-9D8E1C6A64A1.png" height="992" width="1378"/></div>
<div>4、在maven的setting.xml【我本机上的路径：/Users/me/.m2/】，添加标黄的部分，目的：让maven在发布项目的时候用该用户名和密码访问tomcat。</div>
<div><br/></div>
<div>
<hr/></div>
<div>     &lt;servers&gt;</div>
<div>
<div>        &lt;!--</div>
<div>        &lt;server&gt;</div>
<div>            &lt;id&gt;repo-iss&lt;/id&gt;</div>
<div>            &lt;username&gt;deployment&lt;/username&gt;</div>
<div>            &lt;password&gt;deployment123&lt;/password&gt;</div>
<div>        &lt;/server&gt;</div>
<div>        --&gt;</div>
<div>        <span style="background-color: rgb(255, 250, 165);-evernote-highlight:true;">&lt;server&gt;</span></div>
<div><span style="background-color: rgb(255, 250, 165);-evernote-highlight:true;">            &lt;id&gt;tomcat&lt;/id&gt;</span></div>
<div><span style="background-color: rgb(255, 250, 165);-evernote-highlight:true;">            &lt;username&gt;manager&lt;/username&gt;</span></div>
<div><span style="background-color: rgb(255, 250, 165);-evernote-highlight:true;">            &lt;password&gt;admin&lt;/password&gt;</span></div>
<div><span style="background-color: rgb(255, 250, 165);-evernote-highlight:true;">        &lt;/server&gt;</span></div>
</div>
<div>    &lt;/servers&gt;</div>
<div>
<hr/></div>
<div><br/></div>
<div>5、采用Spring to Suite新建一个maven项目，然后在pom.xml中添加如下tomcat插件：</div>
<div>
<hr/></div>
<div><span style="font: 11.0px Monaco; color: #009193">&lt;</span><span style="font: 11.0px Monaco; color: #4e9192">build</span><span style="font: 11.0px Monaco; color: #009193">&gt;</span><span style="font: 11.0px Monaco"><br/></span><span style="font: 11.0px Monaco; color: #009193">&lt;</span><span style="font: 11.0px Monaco; color: #4e9192">finalName</span><span style="font: 11.0px Monaco; color: #009193">&gt;</span><span style="font: 11.0px Monaco">MySpringPro</span><span style="font: 11.0px Monaco; color: #009193">&lt;/</span><span style="font: 11.0px Monaco; color: #4e9192">finalName</span><span style="font: 11.0px Monaco; color: #009193">&gt;</span><span style="font: 11.0px Monaco"><br/></span><span style="font: 11.0px Monaco; color: #009193">&lt;</span><span style="font: 11.0px Monaco; color: #4e9192">plugins</span><span style="font: 11.0px Monaco; color: #009193">&gt;</span><span style="font: 11.0px Monaco"><br/></span><span style="font: 11.0px Monaco; color: #009193">&lt;</span><span style="font: 11.0px Monaco; color: #4e9192">plugin</span><span style="font: 11.0px Monaco; color: #009193">&gt;</span><span style="font: 11.0px Monaco"><br/></span><span style="font: 11.0px Monaco; color: #009193">&lt;</span><span style="font: 11.0px Monaco; color: #4e9192">groupId</span><span style="font: 11.0px Monaco; color: #009193">&gt;</span><span style="font: 11.0px Monaco">org.apache.tomcat.maven</span><span style="font: 11.0px Monaco; color: #009193">&lt;/</span><span style="font: 11.0px Monaco; color: #4e9192">groupId</span><span style="font: 11.0px Monaco; color: #009193">&gt;</span><span style="font: 11.0px Monaco"><br/></span><span style="font: 11.0px Monaco; color: #009193">&lt;</span><span style="font: 11.0px Monaco; color: #4e9192">artifactId</span><span style="font: 11.0px Monaco; color: #009193">&gt;</span><span style="font: 11.0px Monaco">tomcat7-<u>maven</u>-<u>plugin</u></span><span style="font: 11.0px Monaco; color: #009193">&lt;/</span><span style="font: 11.0px Monaco; color: #4e9192">artifactId</span><span style="font: 11.0px Monaco; color: #009193">&gt;</span><span style="font: 11.0px Monaco"><br/></span><span style="font: 11.0px Monaco; color: #009193">&lt;</span><span style="font: 11.0px Monaco; color: #4e9192">version</span><span style="font: 11.0px Monaco; color: #009193">&gt;</span><span style="font: 11.0px Monaco">2.2</span><span style="font: 11.0px Monaco; color: #009193">&lt;/</span><span style="font: 11.0px Monaco; color: #4e9192">version</span><span style="font: 11.0px Monaco; color: #009193">&gt;</span><span style="font: 11.0px Monaco"><br/>
<br/></span><span style="font: 11.0px Monaco; color: #4f76cb">&lt;!-- 告诉<u>maven</u>用manager/<u>admin</u>账号访问setting.xml中id为<u>tomcat</u>的服务器，去http://localhost:8080/manager/html这个地址发布我的项目 --&gt;</span><span style="font: 11.0px Monaco"><br/></span><span style="font: 11.0px Monaco; color: #009193">&lt;</span><span style="font: 11.0px Monaco; color: #4e9192">configuration</span><span style="font: 11.0px Monaco; color: #009193">&gt;</span><span style="font: 11.0px Monaco"><br/></span><span style="font: 11.0px Monaco; color: #009193">&lt;</span><span style="font: 11.0px Monaco; color: #4e9192">url</span><span style="font: 11.0px Monaco; color: #009193">&gt;</span><span style="font: 11.0px Monaco"><a href="http://localhost:8080/manager/text">http://localhost:8080/manager/text</a></span><span style="font: 11.0px Monaco; color: #009193">&lt;/</span><span style="font: 11.0px Monaco; color: #4e9192">url</span><span style="font: 11.0px Monaco; color: #009193">&gt;</span><span style="font: 11.0px Monaco"><br/></span><span style="font: 11.0px Monaco; color: #009193">&lt;</span><span style="font: 11.0px Monaco; color: #4e9192">server</span><span style="font: 11.0px Monaco; color: #009193">&gt;</span><span style="font: 11.0px Monaco">tomcat</span><span style="font: 11.0px Monaco; color: #009193">&lt;/</span><span style="font: 11.0px Monaco; color: #4e9192">server</span><span style="font: 11.0px Monaco; color: #009193">&gt;</span><span style="font: 11.0px Monaco"><br/></span><span style="font: 11.0px Monaco; color: #009193">&lt;</span><span style="font: 11.0px Monaco; color: #4e9192">username</span><span style="font: 11.0px Monaco; color: #009193">&gt;</span><span style="font: 11.0px Monaco">manager</span><span style="font: 11.0px Monaco; color: #009193">&lt;/</span><span style="font: 11.0px Monaco; color: #4e9192">username</span><span style="font: 11.0px Monaco; color: #009193">&gt;</span><span style="font: 11.0px Monaco"><br/></span><span style="font: 11.0px Monaco; color: #009193">&lt;</span><span style="font: 11.0px Monaco; color: #4e9192">password</span><span style="font: 11.0px Monaco; color: #009193">&gt;</span><span style="font: 11.0px Monaco">admin</span><span style="font: 11.0px Monaco; color: #009193">&lt;/</span><span style="font: 11.0px Monaco; color: #4e9192">password</span><span style="font: 11.0px Monaco; color: #009193">&gt;</span><span style="font: 11.0px Monaco"><br/></span><span style="font: 11.0px Monaco; color: #009193">&lt;/</span><span style="font: 11.0px Monaco; color: #4e9192">configuration</span><span style="font: 11.0px Monaco; color: #009193">&gt;</span><span style="font: 11.0px Monaco"><br/></span><span style="font: 11.0px Monaco; color: #009193">&lt;/</span><span style="font: 11.0px Monaco; color: #4e9192">plugin</span><span style="font: 11.0px Monaco; color: #009193">&gt;</span><span style="font: 11.0px Monaco"><br/></span><span style="font: 11.0px Monaco; color: #009193">&lt;/</span><span style="font: 11.0px Monaco; color: #4e9192">plugins</span><span style="font: 11.0px Monaco; color: #009193">&gt;</span></div>
<div><span style="font-family: Monaco;"><span style="font-size: 11px;"><span style="font: 11.0px Monaco; color: #009193">&lt;/</span><span style="font: 11.0px Monaco; color: #4e9192">build</span><span style="font: 11.0px Monaco; color: #009193">&gt;</span></span></span></div>
<div>
<hr/></div>
<div>一定要记得url是<a href="http://localhost:8080/manager/html">http://localhost:8080/manager/text</a>，之前弄成了<a href="http://localhost:8080/manager/html">http://localhost:8080/manager/html</a>，导致一直deploy失败。</div>
<div><br/></div>
<div>6、然后就可以右键项目，Run As -&gt; Maven build…，设置如下：</div>
<div><img src="Maven-tomcat%E9%83%A8%E7%BD%B2%E8%BF%87%E7%A8%8B.resources/F32F1CA4-B03B-4828-B0CA-114CAA948CE6.png" height="754" width="985"/>tomcat7:redeploy -e，-e的作用是当deploy失败的时候会将异常信息打印在Console，方便排错。</div>
<div><br/></div>
<div>7、终于部署成功：</div>
<div><img src="Maven-tomcat%E9%83%A8%E7%BD%B2%E8%BF%87%E7%A8%8B.resources/8EDEF6CF-5D8D-4048-8BEC-27F06D83C782.png" height="908" width="1426"/></div>
<div><br/></div>
<div>8、浏览器访问<a href="http://localhost:8080/MySpringPro/">http://localhost:8080/MySpringPro/</a>，成功。</div>
<div><br/></div>
<div>另外：</div>
<div>tomcat官网上的Plugin Documentation:</div>
<div><a href="http://tomcat.apache.org/maven-plugin-2.0/tomcat7-maven-plugin/plugin-info.html">http://tomcat.apache.org/maven-plugin-2.0/tomcat7-maven-plugin/plugin-info.html</a></div>
<div><br/></div>
</body></html>